from scipy.spatial import KDTree
import numpy as np
import random
import cProfile

class GV:
    D = 50 #dimension
    N = 1000 #point number
    K = 1000 # number of point to return
    pts = []
    xs = []
    tree = 0
 
def init():
    GV.pts = [[random.randint(0,100) for d in range(GV.D)] for n in range(GV.N)]
    GV.xs = np.array([[random.randint(0,100) for d in range(GV.D)]])

def calTree():
    GV.tree = KDTree(GV.pts)

def query():
    distances, indexes = GV.tree.query(x = GV.xs, k = GV.K)
    for k in range(GV.K):
        print distances[0][k], GV.pts[indexes[0][k]]

def kdquery():
    init()
    calTree()
    query()

cProfile.run('kdquery()')
